import java.io.File;
import java.nio.file.Files;

public class XORCipher {
//    签名为k
    private static final char sign = 'k';
//    异或加密
    private static String encrypt(String text){
        StringBuffer sb = new StringBuffer();
        char c;
        for(int i=0;i<text.length();i++){
            c = text.charAt(i);
            c = (char) (c^sign);
            sb.append(c);
        }
        return sb.toString();
    }

    //  加解密敏感词库
    public static void main(String[] args) throws Exception {
        String dir = ".\\敏感词库";
        File dire = new File(dir);
        File[] files = dire.listFiles();

        String context;
        for(File file:files){
            context = new String(Files.readAllBytes(file.toPath()));
            context = encrypt(context);
            Files.write(file.toPath(),context.getBytes());
        }
        System.out.println("操作完成！");
    }




////  加密算法测试案例
//    public static void main(String[] args) {
//        String text = "Kingner is me. \n Isla is my lover. \n Chloe is my lover too.\n我就是我-_-\n\"Hello, 世界! \uD83D\uDC4B\uD83C\uDF0D\";";
//        System.out.println(text);
//        String encryptS = encrypt(text);
//        System.out.println(encryptS);
//        String decryptS = encrypt(encryptS);
//        System.out.println(decryptS);
//    }
}
